package com.qf.springbootproject.index.controller;


import com.qf.springbootproject.index.entity.Category;
import com.qf.springbootproject.index.entity.IndexImg;
import com.qf.springbootproject.index.entity.Product;
import com.qf.springbootproject.index.service.CategoryService;
import com.qf.springbootproject.index.service.IndexImgService;
import com.qf.springbootproject.index.service.ProductService;
import com.qf.springbootproject.utils.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 轮播图  前端控制器
 * </p>
 *
 * @author yyq
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/index")
@CrossOrigin
@Slf4j
public class IndexController {
    @Autowired
    IndexImgService indexImgService;
    @Autowired
    ProductService productService;
    @Autowired
    CategoryService categoryService;

    /**
     * 轮播图
     *
     * @return
     */
    @RequestMapping("/indeximg")
    public ResultVo indexImg() {
        List<IndexImg> indexImg = indexImgService.indexImg();
        ResultVo ok = ResultVo.ok();
        ok.put("data", indexImg);
        return ok;
    }

    /**
     * 新品推荐
     *
     * @return
     */
    @RequestMapping("/list-recommends")
    public ResultVo product_img() {
        List<Product> productImgList = productService.productImg();
        ResultVo ok = ResultVo.ok();
        ok.put("data", productImgList);
        return ok;
    }

    /**
     * 分类列表
     *
     * @return
     */
    @GetMapping("/category-list")
    public ResultVo categoryList() {
        List<Category> categories = categoryService.categoryList();
        ResultVo ok = ResultVo.ok();
        ok.put("data", categories);
        return ok;
    }

    /**
     * 销量商品分类
     *
     * @return
     */
    //@RequestMapping("/category-recommends")
    public ResultVo CategoryProducts() {
        List<Category> categoryList = categoryService.CategoryProducts();
        ResultVo ok = ResultVo.ok();
        ok.put("data", categoryList);
        return ok;
    }

    /**
     * 销量商品分类代码优化
     *
     * @return
     */
    @RequestMapping("/category-recommends")
    public ResultVo CategoryRecommends() {
        List<Category> categoryList = categoryService.CategoryRecommends();
        ResultVo ok = ResultVo.ok();
        ok.put("data", categoryList);
        return ok;
    }
}












